
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.Interfaces; 
using JGSY.CMS.LowCode.Platform.Application.DTOs;

namespace JGSY.CMS.LowCode.Platform.Application.Services
{
    /// <summary>
    /// 安全管理应用服务。
    /// 提供安全指标监控、威胁检测、设备管理、地理位置登录监控和登录历史等安全相关业务功能。
    /// </summary>
    [JGSY.CMS.LowCode.Platform.Infrastructure.Services.LogOperation]
    public class SecurityAppService : ISecurityAppService
    {
        /// <summary>
        /// 安全服务接口
        /// </summary>
        private readonly Interfaces.ISecurityService _securityService;
        
        /// <summary>
        /// 构造函数，注入安全服务
        /// </summary>
        /// <param name="securityService">安全服务接口</param>
        public SecurityAppService(Interfaces.ISecurityService securityService)
        {
            _securityService = securityService;
        }

        /// <summary>
        /// 获取安全指标统计数据
        /// </summary>
        /// <returns>安全指标数据传输对象</returns>
        public async Task<SecurityMetricsDto> GetMetricsAsync()
        {
            return await _securityService.GetMetricsAsync();
        }

        /// <summary>
        /// 分页获取威胁信息
        /// </summary>
        /// <param name="severity">威胁严重程度</param>
        /// <param name="page">页码，默认为1</param>
        /// <param name="limit">每页数量，默认为10</param>
        /// <returns>威胁信息列表</returns>
        public async Task<IEnumerable<ThreatDto>> GetThreatsAsync(string severity, int page = 1, int limit = 10)
        {
            return await _securityService.GetThreatsAsync(severity, page, limit);
        }

        /// <summary>
        /// 获取地理位置登录记录
        /// </summary>
        /// <param name="days">查询天数，默认为7天</param>
        /// <returns>地理位置登录记录列表</returns>
        public async Task<IEnumerable<GeographicLoginDto>> GetGeographicLoginsAsync(int days = 7)
        {
            return await _securityService.GetGeographicLoginsAsync(days);
        }

        /// <summary>
        /// 获取设备列表
        /// </summary>
        /// <returns>设备信息列表</returns>
        public async Task<IEnumerable<DeviceDto>> GetDevicesAsync()
        {
            return await _securityService.GetDevicesAsync();
        }

        /// <summary>
        /// 信任指定设备
        /// </summary>
        /// <param name="deviceId">设备标识符</param>
        /// <returns>信任操作任务</returns>
        public async Task TrustDeviceAsync(long deviceId)
        {
            await _securityService.TrustDeviceAsync(deviceId);
        }
        
        /// <summary>
        /// 移除指定设备
        /// </summary>
        /// <param name="deviceId">设备标识符</param>
        /// <returns>移除操作任务</returns>
        public async Task RemoveDeviceAsync(long deviceId)
        {
            await _securityService.RemoveDeviceAsync(deviceId);
        }
        
        /// <summary>
        /// 分页获取登录历史记录
        /// </summary>
        /// <param name="page">页码，默认为1</param>
        /// <param name="limit">每页数量，默认为10</param>
        /// <param name="startDate">开始日期</param>
        /// <param name="endDate">结束日期</param>
        /// <returns>登录历史记录列表</returns>
        public async Task<IEnumerable<LoginHistoryDto>> GetLoginHistoryAsync(int page = 1, int limit = 10, string? startDate = null, string? endDate = null)
        {
            return await _securityService.GetLoginHistoryAsync(page, limit, startDate, endDate);
        }
    }
}
   